package com.hoperun.product.activity;

import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hoperun.product.Models.DaoshaModel;
import com.hoperun.product.Models.UserModel;
import com.hoperun.product.base.MIP_BaseActivity;
import com.hoperun.product.net.IServiceImpl;
import com.hoperun.product.net.RequestServiceImpl;
import com.hoperun.product.util.ParseUtils;
import com.hoperun.product.util.SharedPreUtil;
import com.hoperun.product.view.SimpleDialog;
import com.hoperun.product.wgyutil.WgyUtil;
import com.hoperun.yieldmgr.R;

import org.json.JSONArray;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DaoshaActivity extends MIP_BaseActivity {

    @BindView(R.id.input_dateTv)
    TextView inputDateTv;
    @BindView(R.id.query_chooseDateImg)
    ImageView queryChooseDateImg;
    @BindView(R.id.input_dateLl)
    LinearLayout inputDateLl;
    @BindView(R.id.query_zhibie)
    EditText queryZhibie;
    @BindView(R.id.spinnergongzhong)
    Spinner spinnergongzhong;
    @BindView(R.id.input_searchBtn)
    Button inputSearchBtn;
    @BindView(R.id.qu_pihao)
    EditText quPihao;
    @BindView(R.id.qu_zhibie)
    EditText quZhibie;
    @BindView(R.id.btnqusha)
    Button btnqusha;
    @BindView(R.id.input_deleteBtn)
    Button inputDeleteBtn;
    @BindView(R.id.input_saveBtn)
    Button inputSaveBtn;

    @BindView(R.id.input_nodateImg)
    ImageView inputNodateImg;

    QuickAdapter quickAdapter;
    ArrayList<DaoshaModel> daolist = new ArrayList<DaoshaModel>();
    ArrayList<DaoshaModel> deletedaolist = new ArrayList<DaoshaModel>();
    ArrayList<DaoshaModel> savedaolist = new ArrayList<DaoshaModel>();
    @BindView(R.id.query_pihao)
    EditText queryPihao;
    @BindView(R.id.qu_ganghao)
    EditText quGanghao;
    private int mCount = 0;
    @BindView(R.id.recylistview)
    RecyclerView recylistview;
    //工种
    ArrayAdapter gongzhongSpinnerAdapter;
    ArrayList<String> gongstrlist = new ArrayList<String>();

    //日期
    String mJobDate;
    private SimpleDateFormat dateFormat_ZH = new SimpleDateFormat("yyyy年MM月dd日");
    private SimpleDateFormat dateFormat_EN = new SimpleDateFormat("yyyy-MM-dd");

    UserModel userModel = null;
    EditDialog.Builder dialog = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_daosha);
        ButterKnife.bind(this);
        try {
            String jsonuser = SharedPreUtil.getValue(this, SharedPreUtil.USERBEAN, "").toString();
            userModel = ParseUtils.parse(jsonuser, UserModel.class);
            //初始化日期
            mJobDate = userModel.getJobDate();//dateFormat_EN.format(new Date(System.currentTimeMillis()));
            inputDateTv.setText(dateFormat_ZH.format(dateFormat_EN.parse(userModel.getJobDate())));
        } catch (Exception e) {
        }

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recylistview.setLayoutManager(layoutManager);
        //给RecyclerView设置适配器
        quickAdapter = new QuickAdapter();
        recylistview.setAdapter(quickAdapter);
        //工种
        gongzhongSpinnerAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, gongstrlist);
        gongzhongSpinnerAdapter.setDropDownViewResource(R.layout.spinner_drop_item);
        spinnergongzhong.setAdapter(gongzhongSpinnerAdapter);
        //默认查
        querylist(mJobDate, "", userModel.getJobNum(), "", "");
        //工种
        getG();

    }


    public class QuickAdapter extends BaseQuickAdapter<DaoshaModel, BaseViewHolder> {
        public QuickAdapter() {
            super(R.layout.dao_list_item, daolist);
        }


        @Override
        protected void convert(final BaseViewHolder holder, DaoshaModel item) {
            TextView item_banci = holder.getView(R.id.item_banci);//班次
            final EditText input_daobanci = holder.getView(R.id.input_daobanci);//倒班次
            TextView item_gonghao = holder.getView(R.id.item_gonghao);//工号
            TextView item_zhibie = holder.getView(R.id.item_zhibie);//支别
            TextView item_shazhiquan = holder.getView(R.id.item_shazhiquan);//纱支全称
            TextView item_sehao = holder.getView(R.id.item_sehao);//色号
            TextView item_gonghuodanwei = holder.getView(R.id.item_gonghuodanwei);//供货单位
            TextView item_pihao = holder.getView(R.id.item_pihao);//批号
            final EditText input_shuliang = holder.getView(R.id.input_shuliang);//
            final EditText input_chesu = holder.getView(R.id.input_chesu);//
            input_chesu.setKeyListener(DigitsKeyListener.getInstance("0123456789"));
            final Spinner item_gong_spinner = holder.getView(R.id.item_gong_spinner);//工种spinner
            CheckBox input_item_checkBox = holder.getView(R.id.input_item_checkBox);
            item_gong_spinner.setAdapter(gongzhongSpinnerAdapter);
            for (int i = 0; i < gongstrlist.size(); i++) {
                if (gongstrlist.get(i).equals(item.getWorktype())) {
                    item_gong_spinner.setSelection(i);
                }
            }
            item_gong_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
                    String data = (String) item_gong_spinner.getItemAtPosition(position);
                    if (!data.equals("请选择")) {
                        daolist.get(holder.getLayoutPosition()).setWorktype(data);
                    }

                }

                @Override
                public void onNothingSelected(AdapterView<?> adapterView) {

                }
            });
            input_item_checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    daolist.get(holder.getLayoutPosition()).setBoxcheck(isChecked);
//                    mCount = 0;
//                    for (int i = 0; i < daolist.size(); i++) {
//                        if (daolist.get(i).isBoxcheck() == true) {
//                            mCount++;
//                        }
//                    }
                }
            });
            input_shuliang.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                    daolist.get(holder.getLayoutPosition()).setKilonum(input_shuliang.getText().toString());
                }

                @Override
                public void afterTextChanged(Editable editable) {

                }
            });

            input_chesu.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                    daolist.get(holder.getLayoutPosition()).setDutyspeed(input_chesu.getText().toString());
                }

                @Override
                public void afterTextChanged(Editable editable) {

                }
            });

            input_daobanci.addTextChangedListener(new TextWatcher() {
                private int selectionStart;
                private int selectionEnd;
                private CharSequence temp;

                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                    temp = charSequence;
                    daolist.get(holder.getLayoutPosition()).setSpclass(input_daobanci.getText().toString());
                }

                @Override
                public void afterTextChanged(Editable s) {
                    selectionStart = input_daobanci.getSelectionStart();
                    selectionEnd = input_daobanci.getSelectionEnd();
                    if (input_daobanci.getEditableText().toString().length() > 0) {
                        if (Float.parseFloat(input_daobanci.getEditableText().toString()) > 1) {
                            input_daobanci.setText("");
                        } else {
                            if (!WgyUtil.isOnlyonePointNumber(input_daobanci.getEditableText().toString())) {
                                s.delete(selectionStart - 1, selectionEnd);
                                input_daobanci.setText(s);
                            }
                        }
                    }

                }
            });
            item_banci.setText(item.getProclass() == null ? "" : item.getProclass());
            input_daobanci.setText(item.getSpclass() == null ? "" : item.getSpclass());
            item_gonghao.setText(item.getJobnum() == null ? "" : item.getJobnum());
            item_zhibie.setText(item.getCottype() == null ? "" : item.getCottype());
            item_shazhiquan.setText(item.getSzqc() == null ? "" : item.getSzqc());
            item_sehao.setText(item.getColorno() == null ? "" : item.getColorno());
            item_gonghuodanwei.setText(item.getOriplace() == null ? "" : item.getOriplace());
            item_pihao.setText(item.getBatchno() == null ? "" : item.getBatchno());
            input_shuliang.setText(item.getKilonum() == null ? "" : item.getKilonum());
            input_chesu.setText(item.getDutyspeed() == null ? "" : item.getDutyspeed());
            input_item_checkBox.setChecked(item.isBoxcheck());

        }
    }

    public void getDateList() {//根据日期查询是否可插入
        showWait();
        RequestServiceImpl.getdatelist(mMIPHandler, IServiceImpl.DSRCLLR_GetExistCount_M, "2018-12-09");
    }

    public void getG() {//获取工种
        showWait();
        RequestServiceImpl.querygz(mMIPHandler, IServiceImpl.querygz);
    }


    public void querylist(String JobDate, String ph, String gh, String zb, String gz) {//根据条件查询
        showWait();
        RequestServiceImpl.querydaolist(mMIPHandler, IServiceImpl.querydaolist, JobDate, ph, gh, zb, gz);
    }


    @Override
    public void onPostHandle(int requestType, Object objBody, boolean error) throws Exception {
        String msg = "";
        String opt = "";
        if (error) {
            if (requestType != IServiceImpl.getYuanliaoInfo) {
                stopWait();
            }
            switch (requestType) {
                case IServiceImpl.DSRCLLR_GetExistCount_M://根据日期获取
                    try {
                        JSONObject jsonObj = new JSONObject((String) objBody);
                        if (jsonObj.getInt("Code") == 0) {

                        }
                    } catch (Exception e) {

                    }
                    break;
                case IServiceImpl.querydaolist://根据条件查询
                    try {
                        JSONObject jsonObj = new JSONObject((String) objBody);
                        if (jsonObj.getInt("Code") == 0) {
                            if (jsonObj.getJSONArray("Result") != null && jsonObj.getJSONArray("Result").length() > 0) {
                                JSONArray jsonArray = jsonObj.getJSONArray("Result");
                                daolist.clear();
                                for (int i = 0; i < jsonArray.length(); i++) {
                                    DaoshaModel daoshaModel = ParseUtils.parse(jsonArray.getJSONObject(i).toString(), DaoshaModel.class);
                                    daoshaModel.setBoxcheck(false);
                                    daoshaModel.setUuid(WgyUtil.getUUID());
                                    if (userModel != null) {
                                        daoshaModel.setCreater(userModel.getJobNum());
                                        daoshaModel.setCrename(userModel.getJobName());
                                        daoshaModel.setUpdater(userModel.getJobNum());
                                        daoshaModel.setUpdname(userModel.getJobName());
                                    }
                                    daolist.add(daoshaModel);
                                }
                            } else {
                                daolist.clear();
                            }
                            quickAdapter.notifyDataSetChanged();
                            checkListview();

                        } else {
                            SimpleDialog.show(this, jsonObj.getString("Message"));
                        }
                    } catch (Exception e) {

                    }
                    break;
                case IServiceImpl.querygz://获取工种
                    try {
                        JSONObject jsonObj = new JSONObject((String) objBody);
                        if (jsonObj.getInt("Code") == 0) {
                            JSONArray jsonArray = jsonObj.getJSONArray("Result");
                            for (int i = 0; i < jsonArray.length(); i++) {
                                gongstrlist.add(jsonArray.getString(i));
                            }
                            gongstrlist.add(0, "请选择");
                            quickAdapter.notifyDataSetChanged();
                            gongzhongSpinnerAdapter.notifyDataSetChanged();
                        }
                    } catch (Exception e) {

                    }
                    break;
                case IServiceImpl.getYuanliaoInfo://获取原料信息
                    try {
                        final JSONObject jsonObj = new JSONObject((String) objBody);
                        if (jsonObj.getInt("Code") == 0) {
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    try {
                                        JSONArray jsonArray = jsonObj.getJSONArray("Result");
                                        if (jsonArray != null && jsonArray.length() > 0) {
                                            final List<DaoshaModel> inputlist = new ArrayList<DaoshaModel>();
                                            for (int i = 0; i < jsonArray.length(); i++) {
                                                DaoshaModel daoshaModel = ParseUtils.parse(WgyUtil.transToLowerObject(jsonArray.getJSONObject(i)).toString(), DaoshaModel.class);
                                                daoshaModel.setBoxcheck(false);
                                                daoshaModel.setSpclass("1");
                                                //daoshaModel.setKilonum("0");
                                                daoshaModel.setJobdate(mJobDate);
                                                if (userModel != null) {
                                                    daoshaModel.setProclass(userModel.getBC());
                                                    daoshaModel.setJobnum(userModel.getJobNum());
                                                    daoshaModel.setCreater(userModel.getJobNum());
                                                    daoshaModel.setCrename(userModel.getJobName());
                                                    daoshaModel.setUpdater(userModel.getJobNum());
                                                    daoshaModel.setUpdname(userModel.getJobName());
                                                }
                                                daoshaModel.setUuid(WgyUtil.getUUID());
                                                inputlist.add(daoshaModel);
                                            }
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    DialogQusha(inputlist);
                                                }
                                            });

                                        } else {
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    stopWait();
                                                    SimpleDialog.show(DaoshaActivity.this, "暂无原料信息！");
                                                }
                                            });
                                        }

                                    } catch (Exception e) {
                                        runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                stopWait();
                                            }
                                        });
                                    }
                                }
                            }).start();

                        } else {

                            stopWait();
                        }
                    } catch (Exception e) {

                    }
                    break;

                case IServiceImpl.qusha_ganghao:
                    try {
                        final JSONObject jsonObj = new JSONObject((String) objBody);
                        if (jsonObj.getInt("Code") == 0) {
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    try {
                                        JSONArray jsonArray = jsonObj.getJSONArray("Result");
                                        if (jsonArray != null && jsonArray.length() > 0) {
                                            final List<DaoshaModel> inputlist = new ArrayList<DaoshaModel>();
                                            for (int i = 0; i < jsonArray.length(); i++) {
                                                DaoshaModel daoshaModel = ParseUtils.parse(WgyUtil.transToLowerObject(jsonArray.getJSONObject(i)).toString(), DaoshaModel.class);
                                                daoshaModel.setBoxcheck(false);
                                                daoshaModel.setSpclass("1");
                                                //daoshaModel.setKilonum("0");
                                                daoshaModel.setJobdate(mJobDate);
                                                if (userModel != null) {
                                                    daoshaModel.setProclass(userModel.getBC());
                                                    daoshaModel.setJobnum(userModel.getJobNum());
                                                    daoshaModel.setCreater(userModel.getJobNum());
                                                    daoshaModel.setCrename(userModel.getJobName());
                                                    daoshaModel.setUpdater(userModel.getJobNum());
                                                    daoshaModel.setUpdname(userModel.getJobName());
                                                }
                                                daoshaModel.setUuid(WgyUtil.getUUID());
                                                inputlist.add(daoshaModel);
                                            }
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    DialogQusha(inputlist);
                                                }
                                            });

                                        } else {
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    stopWait();
                                                    SimpleDialog.show(DaoshaActivity.this, "暂无原料信息！");
                                                }
                                            });
                                        }

                                    } catch (Exception e) {
                                        runOnUiThread(new Runnable() {
                                            @Override
                                            public void run() {
                                                stopWait();
                                            }
                                        });
                                    }
                                }
                            }).start();

                        } else {

                            stopWait();
                        }
                    } catch (Exception e) {

                    }
                    break;
                case IServiceImpl.updateDaosha://更新
                    try {
                        JSONObject jsonObj = new JSONObject((String) objBody);
                        if (jsonObj.getInt("Code") == 0) {
                            SimpleDialog.show(this, "您已成功保存数据！");
//                            for (int i = 0; i < daolist.size(); i++) {
//                                daolist.get(i).setBoxcheck(false);
//                            }
                            //刷新请求
                            String gong = spinnergongzhong.getSelectedItem().toString();
                            if (gong.equals("请选择")) {
                                gong = "";
                            }
                            querylist(mJobDate, queryPihao.getEditableText().toString().trim(), userModel.getJobNum(), queryZhibie.getEditableText().toString().trim(), gong);

                        } else {
                            SimpleDialog.show(this, jsonObj.getString("Message"));
                        }
                    } catch (Exception e) {

                    }
                    break;
                case IServiceImpl.deleteDaosha://删除成功
                    try {
                        JSONObject jsonObj = new JSONObject((String) objBody);
                        if (jsonObj.getInt("Code") == 0) {
                            SimpleDialog.show(this, "您已成功删除数据！");
                            for (int i = 0; i < deletedaolist.size(); i++) {
                                for (int j = 0; j < daolist.size(); j++) {
                                    if (daolist.get(j).getUuid().equals(deletedaolist.get(i).getUuid())) {
                                        daolist.remove(j);
                                    }
                                }
                            }
                            deletedaolist.clear();
                            quickAdapter.notifyDataSetChanged();
                            checkListview();
                        } else {
                            SimpleDialog.show(this, jsonObj.getString("Message"));
                        }
                    } catch (Exception e) {

                    }
                    break;

                case IServiceImpl.valid_shazhi_youxiao:
                    try {
                        JSONObject jsonObject = new JSONObject((String) objBody);
                        if (jsonObject.getInt("Code") == 0) {
                            if (jsonObject.getJSONArray("Result") != null && jsonObject.getJSONArray("Result").length() > 0) {
                                JSONArray jsonArray = jsonObject.getJSONArray("Result");
                                String errorstr = "";
                                for (int i = 0; i < jsonArray.length(); i++) {
                                    JSONObject one = jsonArray.getJSONObject(i);
                                    if (one.getString("STDCOTTYPE") != null) {
                                        for (DaoshaModel daoshaModel : dialog.selectinputlist) {
                                            if (daoshaModel.getSzqc().equals(one.getString("SZQC"))) {
                                                daoshaModel.setStdcottype(one.getString("STDCOTTYPE"));
                                                daoshaModel.setStdcottypeValue(one.getString("stdcottypeValue"));
                                            }
                                        }
                                    } else {
                                        errorstr += one.getString("SZQC") + ",";
                                    }
                                }

                                for (DaoshaModel daoshaModel : dialog.selectinputlist) {
                                    if (daoshaModel.getStdcottype() == null) {
                                        dialog.selectinputlist.remove(daoshaModel);
                                    }
                                }

                                if (dialog.selectinputlist.size() > 0) {
                                    for (DaoshaModel daoshaModel : dialog.selectinputlist) {
                                        boolean ishave = false;
                                        for (DaoshaModel havemodel : daolist) {
                                            if (havemodel.getUuid().equals(daoshaModel.getUuid())) {
                                                ishave = true;
                                                break;
                                            }
                                        }
                                        if (!ishave) {
                                            daolist.add(0, daoshaModel);
                                        }

                                    }
                                    quickAdapter.notifyDataSetChanged();
                                    checkListview();
                                }

                                if (errorstr.length() > 0) {
                                    SimpleDialog.show(this, errorstr.substring(0, errorstr.length() - 1) + "数据异常");
                                }
                            }

                        } else {
                            SimpleDialog.show(this, jsonObject.getString("Message"));
                        }
                    } catch (Exception e) {

                    }
                    break;

            }

        } else {
            stopWait();
            Toast.makeText(this, "操作失败", Toast.LENGTH_SHORT).show();

        }

    }

    /**
     * 检查listview是否为空
     */
    private void checkListview() {
        if (daolist.size() > 0) {
            recylistview.setVisibility(View.VISIBLE);
        } else {
            recylistview.setVisibility(View.GONE);
        }
    }

    @OnClick({R.id.btnqusha, R.id.input_deleteBtn, R.id.input_saveBtn, R.id.input_dateLl, R.id.input_searchBtn,R.id.btnqushaganhao})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.input_searchBtn:
                String gong = spinnergongzhong.getSelectedItem().toString();
                if (gong.equals("请选择")) {
                    gong = "";
                }
                querylist(mJobDate, queryPihao.getEditableText().toString().trim(), userModel.getJobNum(), queryZhibie.getEditableText().toString().trim(), gong);

                break;
            case R.id.input_dateLl:
                setDate();
                break;
            case R.id.btnqusha:
                if (quPihao.getEditableText().toString().trim().length() == 0 && quZhibie.getEditableText().toString().trim().length() == 0) {
                    SimpleDialog.show(this, "请输入批号或支别");
                    return;
                }
                showWait();
                RequestServiceImpl.getYuanliaoInfo(mMIPHandler, IServiceImpl.getYuanliaoInfo, quPihao.getEditableText().toString().trim(), quZhibie.getEditableText().toString().trim());
                break;
            case R.id.btnqushaganhao:
                if (quGanghao.getEditableText().toString().trim().length() == 0) {
                    SimpleDialog.show(this, "请输入缸号");
                    return;
                }
                showWait();
                RequestServiceImpl.getYuanliaoFromGaohao(mMIPHandler, IServiceImpl.qusha_ganghao, quGanghao.getEditableText().toString().trim());
            break;
            case R.id.input_deleteBtn:
                List<String> PKIDList = new ArrayList<String>();
                for (int i = 0; i < daolist.size(); i++) {
                    if (daolist.get(i).isBoxcheck()) {
                        deletedaolist.add(daolist.get(i));
                        // 添加到需要保存的列表中
                        if (!TextUtils.isEmpty(daolist.get(i).getPkid())) {
                            PKIDList.add(daolist.get(i).getPkid());
                        }

                    }
                }
                if (deletedaolist.size() == 0) {
                    SimpleDialog.show(this, "请勾选需要删除的数据！");
                    stopWait();
                    return;
                }
                if (daolist.size() == 0) {
                    SimpleDialog.show(this, "当前列表为空，请添加数据！");
                    stopWait();
                    return;
                }

                if (PKIDList.size() > 0) {
                    showWait();
                    RequestServiceImpl.deleteDaosha(mMIPHandler, IServiceImpl.deleteDaosha, PKIDList, userModel.getJobNum(), userModel.getJobName());
                } else {
                    for (int i = 0; i < deletedaolist.size(); i++) {
                        for (int j = 0; j < daolist.size(); j++) {
                            if (daolist.get(j).getUuid().equals(deletedaolist.get(i).getUuid())) {
                                daolist.remove(j);
                            }
                        }
                    }
                    deletedaolist.clear();
                    quickAdapter.notifyDataSetChanged();
                }


                break;
            case R.id.input_saveBtn://保存数据
                savedaolist.clear();
                for (int i = 0; i < daolist.size(); i++) {
                    if (daolist.get(i).isBoxcheck()) {
                        // 添加到需要保存的列表中
                        savedaolist.add(daolist.get(i));
                    }
                }
                if (daolist.size() == 0) {
                    SimpleDialog.show(this, "当前列表为空，请添加数据！");
                    stopWait();
                    return;
                }

                if (savedaolist.size() == 0) {
                    SimpleDialog.show(this, "请勾选需要保存的数据！");
                    stopWait();
                    return;
                }
                for (DaoshaModel product : savedaolist) {
                    if (TextUtils.isEmpty(product.getSpclass())) {
                        SimpleDialog.show(this, "倒纱班次不能为空！");
                        stopWait();
                        return;
                    }
                    if (Float.parseFloat(product.getSpclass()) == 0) {
                        SimpleDialog.show(this, "倒纱班次不能为0！");
                        stopWait();
                        return;
                    }

                    if (TextUtils.isEmpty(product.getDutyspeed())) {
                        SimpleDialog.show(this, "当班车速不能为空！");
                        stopWait();
                        return;
                    }
                    if (Float.parseFloat(product.getDutyspeed()) == 0) {
                        SimpleDialog.show(this, "当班车速不能为0！");
                        stopWait();
                        return;
                    }


                    if (TextUtils.isEmpty(product.getKilonum())) {
                        SimpleDialog.show(this, "数量不能为空！");
                        stopWait();
                        return;
                    }
                    if (Float.parseFloat(product.getKilonum()) == 0) {
                        SimpleDialog.show(this, "数量不能为0！");
                        stopWait();
                        return;
                    }

                    if (TextUtils.isEmpty(product.getWorktype())) {
                        SimpleDialog.show(this, "请选择工种");
                        stopWait();
                        return;
                    }
                }

                showWait();
                RequestServiceImpl.updateDaosha(mMIPHandler, IServiceImpl.updateDaosha, savedaolist);
                break;
        }
    }


    public void DialogQusha(List<DaoshaModel> inputlist) {//取纱
        stopWait();
        dialog = new EditDialog.Builder(this);
        dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        // ;
                        dialog.selectinputlist.clear();
                        for (int j = 0; j < dialog.inputlist.size(); j++) {
                            if (dialog.inputlist.get(j).isBoxcheck()) {
                                // 添加到需要保存的列表中
                                dialog.selectinputlist.add(dialog.inputlist.get(j));
                            }
                        }
                        if (dialog.inputlist.size() == 0) {
                            SimpleDialog.show(DaoshaActivity.this, "当前列表为空！");
                            return;
                        }

                        if (dialog.selectinputlist.size() == 0) {
                            SimpleDialog.show(DaoshaActivity.this, "请勾选需要导入的数据！");
                            return;
                        }

                        showWait();
                        RequestServiceImpl.validshaok(mMIPHandler, IServiceImpl.valid_shazhi_youxiao, dialog.selectinputlist);
                        dialogInterface.dismiss();
                    }
                }

        ).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                }
        ).create().show();
        dialog.setDaoList(inputlist);
    }


    /**
     * 设置日期
     */
    private void setDate() {
        // 初始化日历信息
        Calendar calendar = Calendar.getInstance();
        // 获取当前年月日
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        if (hour < 7 || (hour == 7 && minute < 30)) {
            day -= 1;
        }
        Log.d("setDate", year + "-" + month + "-" + day);
        /**
         * context：当前上下文； callback：OnDateSetListener日期改变监听器； year：初始化的年；
         * monthOfYear：初始化的月（从0开始计数，所以实际应用时需要加1）； dayOfMonth：初始化的日；
         */
        DatePickerDialog datePickerDialog = new DatePickerDialog(this, mOnDateSetListenernew, year, month, day);

        datePickerDialog.show();
    }

    /**
     * 日期选择监听器
     */
    DatePickerDialog.OnDateSetListener mOnDateSetListenernew = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
            String date = year + "年" + String.format("%02d", month + 1) + "月" + String.format("%02d", dayOfMonth) + "日";
            inputDateTv.setText(date);
            mJobDate = year + "-" + String.format("%02d", month + 1) + "-" + String.format("%02d", dayOfMonth);

        }
    };


    private Calendar getDefaultDate() {
        Calendar calendar = Calendar.getInstance();
        // 获取当前年月日
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        if (hour < 7 || (hour == 7 && minute < 30)) {
            day -= 1;
        }
        calendar.set(year, month, day);
        return calendar;
    }

}
